package main

// 创建区块链
type BlockChain struct {
	Blocks []*Block
}

func NewBlockChain() *BlockChain {
	blockChain := BlockChain{
		Blocks: []*Block{},
	}
	// 创世块并加入区块链
	block := blockChain.GenesisBlock()
	blockChain.Blocks = append(blockChain.Blocks, block)
	return &blockChain
}

// 创世块
func (blockChain BlockChain) GenesisBlock() *Block {
	return blockChain.NewBlock("创世块")
}

// 添加区块
func (blockChain *BlockChain) AddBlock(data string) {
	block := blockChain.NewBlock(data)
	blockChain.Blocks = append(blockChain.Blocks, block)

}
